package net.vanchu.mortgagecalculator.common.config;

/**
 * 根据不同的贷款年份，有不同的贷款利率
 * <p/>
 * Created by Granton on 2016/12/19.
 */
public class LoanRate {

    String name;

    float comOne;

    float comOneToThree;

    float comThreeToFive;

    float comFiveAndMore;

    float proOneToFive;

    float proFiveOrMore;

    public LoanRate(String name,
                    float comOne, float comOneToThree, float comThreeToFive, float comFiveAndMore,
                    float proOneToFive, float proFiveOrMore) {
        this.name = name;
        this.comOne = comOne;
        this.comOneToThree = comOneToThree;
        this.comThreeToFive = comThreeToFive;
        this.comFiveAndMore = comFiveAndMore;
        this.proOneToFive = proOneToFive;
        this.proFiveOrMore = proFiveOrMore;
    }

    public float getValue(LoanWay loanWay, int year) {
        if (loanWay == LoanWay.wayCommercial) {
            if (year == 1) {
                return comOne;
            }
            if (year <= 3) {
                return comOneToThree;
            }
            if (year <= 5) {
                return comThreeToFive;
            }
            return comFiveAndMore;
        }
        if (year <= 5) {
            return proOneToFive;
        }
        return proFiveOrMore;
    }
}